package com.huatai.exchange.impl;

import com.faneui.common.exception.BusinessException;
import com.huatai.exchange.dal.dao.*;
import com.huatai.exchange.dal.model.*;
import com.huatai.exchange.service.ExcExchangeInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExcExchangeInfoServiceImpl implements ExcExchangeInfoService {

    private static final Logger logger = LoggerFactory.getLogger(ExcExchangeInfoService.class);

    @Autowired
    private ExcExchangeInfoDAO exchangeInfoDAO;

    @Autowired
    private ExcExchangeDataFileDAO excExchangeDataFileDAO;

    @Override
    public List<ExcExchangeInfo> queryExcExchangeInfoList(ExcExchangeInfo excExchangeInfo) throws BusinessException {
        List<ExcExchangeInfo> excExchangeInfos = null;
        try{
            excExchangeInfos = exchangeInfoDAO.queryByModel(excExchangeInfo) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return excExchangeInfos;
    }

    @Override
    public ExcExchangeInfo queryExcExchangeInfo(String id) throws BusinessException {
        ExcExchangeInfo  excExchangeInfo  = null;
        try{
            excExchangeInfo = exchangeInfoDAO.queryById(id) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return excExchangeInfo;
    }

    @Override
    public void addExcExchangeInfo(ExcExchangeInfo excExchangeInfo) throws BusinessException {
        try{
           exchangeInfoDAO.insert(excExchangeInfo);
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void modifyExcExchangeInfo(ExcExchangeInfo excExchangeInfo) throws BusinessException {
        try{
            Long num = exchangeInfoDAO.updateById(excExchangeInfo) ;
            if(num == 0) {
                throw new BusinessException("更新失败") ;
            }
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void deleteExcExchangeInfo(String id) throws BusinessException {
        try{
            Long num = exchangeInfoDAO.deleteById(id) ;
            if(num == 0) {
                throw new BusinessException("删除失败") ;
            }
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void addExchangeDataFile(String custDataFileId, String dataFileId) throws BusinessException {
        try{
            ExcExchangeDataFile excExchangeDataFile = new ExcExchangeDataFile();
            excExchangeDataFile.setCustDataFileId(custDataFileId);
            excExchangeDataFile.setDataFileId(dataFileId);
            excExchangeDataFileDAO.insert(excExchangeDataFile);
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }
}